<template>
  <div>
    <router-link to="/" class="header-abs" tag="div" v-show="!isHeader">
       <span class="iconfont header-abs-back">&#xe624;</span>
    </router-link>
    <div class="header-fixed" v-show="isHeader" :style="headerStyle">
      景点选择
      <router-link to="/" >
          <span class="iconfont header-fixed-back">&#xe624;</span>
      </router-link>
    </div>
  </div>
</template>
<script>
export default {
  name: 'DetailHeadder',
  data () {
    return {
      isHeader: false,
      headerStyle: {
        opcity: 0
      }
    }
  },
  activated () {
    window.addEventListener('scroll', this.handleShowClick)
  },
  deactivated () {
    window.removeEventListener('scroll', this.handleShowClick)
  },
  methods: {
    handleShowClick () {
      let top = document.documentElement.scrollTop
      if (top > 43) {
        this.isHeader = true
        let opacity = (top - 43) / 140
        opacity = opacity > 1 ? 1 : opacity
        this.headerStyle = {
          opacity
        }
      } else {
        this.isHeader = false
      }
    }
  }
}
</script>
<style lang="scss" scoped>
@import '~styles/variables' ;
  .header-abs{
    width: 0.8rem;
    height: 0.8rem;
    border-radius: 0.4rem;
    text-align: center;
    position: absolute;
    left: 0.2rem;
    top: 0.2rem;
    background: rgba(0,0,0,.8);
    .header-abs-back{
      color: #fff;
      font-size: .4rem;
      line-height: .8rem;
    }
  }
  .header-fixed{
    color: #fff;
    height: $headerHeight;
    line-height: $headerHeight;
    font-size: .32rem;
    text-align: center;
    background: $baseColor;
    position: fixed;
    left: 0;
    top: 0;
    right: 0;
    .header-fixed-back{
      position: absolute;
      left: 0;
      top: 0;
      width: .64rem;
      font-size: .4rem;
      line-height: $headerHeight;
      text-align: center;
      color: #fff;
    }
  }
</style>
